package com.syt.cellphone.information.http

/**
 * @auther zhulei
 * @date : 2020/11/23 15:52
 * @description : 处理成功或者异常的情况
 */
sealed class Result<out T> {

    /**
     * 成功
     */
    data class Success<out T>(val value: T) : Result<T>()

    /**
     * 失败
     */
    data class Failure(val msg: String?) : Result<Nothing>()

}

inline fun <reified T> Result<T>.doSuccess(success: (T) -> Unit) {
    if (this is Result.Success) {
        success(value)
    }
}

inline fun <reified T> Result<T>.doFailure(failure: (String?) -> Unit) {
    if (this is Result.Failure) {
        failure(msg)
    }
}